
package server.view;


import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.TextArea;
import javafx.scene.layout.AnchorPane;
import javafx.scene.text.Font;
import javafx.stage.Stage;
import server.main.server_main;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;


public class ServerView extends Application {

    private Button btn_start, btn_close; 
    public static TextArea textArea_log; 
    private Label label_log; 
    private static DateFormat df; 

    public static void main(String[] args) {
        launch(args);
    }

    public void start(Stage primaryStage) throws Exception {
        df = new SimpleDateFormat("yyyy-MM-dd a hh:mm:ss");

        AnchorPane root = new AnchorPane();
        label_log = new Label("服务器启动界面");
        label_log.setFont(Font.font("微软雅黑", 16));
        label_log.setStyle("-fx-font-weight: bold;");
        AnchorPane.setTopAnchor(label_log, 20.0);
        AnchorPane.setLeftAnchor(label_log, 160.0);
        root.getChildren().add(label_log);
        textArea_log = new TextArea();
        textArea_log.setEditable(false);
        textArea_log.setWrapText(true);
        textArea_log.setMaxWidth(370.0);
        textArea_log.setPrefWidth(370.0);
        textArea_log.setPrefHeight(420.0);
        AnchorPane.setTopAnchor(textArea_log, 50.0);
        AnchorPane.setLeftAnchor(textArea_log, 25.0);
        ScrollPane scrollPane_log = new ScrollPane(textArea_log);
        scrollPane_log.setPrefSize(385, 420);
        AnchorPane.setTopAnchor(scrollPane_log, 50.0);
        AnchorPane.setLeftAnchor(scrollPane_log, 25.0);
        root.getChildren().add(scrollPane_log);

        btn_start = new Button("启动服务器");
        btn_start.setPrefWidth(100);
        btn_start.setPrefHeight(30);
        AnchorPane.setTopAnchor(btn_start, 490.0);
        AnchorPane.setLeftAnchor(btn_start, 75.0);
        btn_start.setOnAction(e->{
        	 server_main server = new server_main();
        	 try {
				server.ServerStart();
			} catch (Exception e1) {
				e1.printStackTrace();
			}
        });
        root.getChildren().add(btn_start);
        btn_close = new Button("关闭服务器");
        AnchorPane.setTopAnchor(btn_close, 490.0);
        AnchorPane.setLeftAnchor(btn_close, 265.0);
        btn_close.setPrefWidth(100);
        btn_close.setPrefHeight(30);
        btn_close.setOnAction(e->{       	
        });
        root.getChildren().add(btn_close);


        Scene scene = new Scene(root, 411, 560);
        primaryStage.setScene(scene);
        primaryStage.setResizable(false);
        primaryStage.show();
    }


    public static void showMsg(String s) {
        textArea_log.appendText(df.format(new Date())+"  "+s+"\n\n");
    }


}
